/**
 * @widoc $.eventHelper
 * @namespace aux
 * @depends styleHelper/$.styleHelper
 * @des 事件辅助接口处理
 * @type object
 * @attr {boolean} msPointerEnabled
 * @attr {string} touchstartEvent
 * @attr {string} touchmoveEvent
 * @attr {string} touchendEvent
 * @attr {string} transformEndEvent
 * @attr {function} {Array}fGetMoveDirection(x0,y0,x1,y1) 判断从 (x0, y0) 到 (x1, y1) 的移动方向：
 *   - [dir0, dir1, bEqual] dir0 为移动较大位移的方向 'u'(up),'d'(down),'l'(left),'r'(right),''
 *   - 若 bEqual=true，则 dir0 与 dir1 的位移相等
 * @attr {function} {string}fGetEventAttr(ev,name) 获取事件对象 ev 中的属性，ev 中不存在 name 对应的属性时，从 ev.originalEvent 中获取
 */
(function(){
    var msPointerEnabled = window.navigator.msPointerEnabled;
    $.eventHelper = {
        msPointerEnabled: msPointerEnabled,
        touchstartEvent: msPointerEnabled ? 'MSPointerDown' : 'touchstart',
        touchmoveEvent: msPointerEnabled ? 'MSPointerMove' : 'touchmove',
        touchendEvent: msPointerEnabled ? 'MSPointerUp' : 'touchend',
        transformEndEvent: (function(){
            var prefix = $.styleHelper.prefix;
            if(prefix === 'webkit' || prefix === 'O'){
                return prefix.toLowerCase() + 'TransitionEnd';
            }
            return 'transitionend';
        }()),
        fGetMoveDirection: function(x0, y0, x1, y1){
            var diffX = x1 - x0,
                diffY = y1 - y0,
                dirX = '',
                dirY = '',
                absX = Math.abs(diffX),
                absY = Math.abs(diffY),
                res;
            if(diffX > 0){
                dirX = 'r';
            }
            else if(diffX < 0){
                dirX = 'l';
            }
            if(diffY > 0){
                dirY = 'd';
            }
            else if(diffY < 0){
                dirY = 'u';
            }

            if(absX === absY){
                res = [dirX, dirY, true];
            }
            else if(absX > absY){// 横向移动
                res = [dirX, dirY];
            }
            else{// 纵向移动
                res = [dirY, dirX]
            }
            return res;
        },
        fGetEventAttr: function(ev, name){
            if(ev){
                return ev[name] ? ev[name] : ev.originalEvent[name];
            }
        }
    };
}());
